<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/admin/js/xadmin.js"></script>

    <script type="text/javascript" charset="utf-8" src="/static/Plug/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/Plug/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="/static/Plug/ueditor/lang/zh-cn/zh-cn.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form" method="post" action="ajax_add_notice" enctype="multipart/form-data">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>球员名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="sportsman" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>

          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>球员图片
              </label>
              <div class="layui-input-inline">
                  <input type="file"  name="pice" required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
         
          <div class="layui-form-item layui-form-text">
              <label for="profile" class="layui-form-label">
                  简介
              </label>
              <div class="layui-input-block">
                  <textarea placeholder="请输入内容" id="profile" name="profile" class="layui-textarea"></textarea>
              </div>
          </div>

          <div class="layui-form-item layui-form-text">
              <label for="content" class="layui-form-label">
                  详情
              </label>
              <div class="layui-input-block">
              <script id="container" name="content" type="text/plain" class="layui-textarea">
                这里写你的初始化内容
              </script>
                
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" type='submit' lay-submit="">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);


            /* $.ajax({
                    url: "{:url('ajax_add_notice')}",
                    type: "POST",
                    data: data.field,
                    async : false,
                    contentType: false,   //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作，从而失去分界符，而使服务器不能正常解析文件
                    enctype: 'multipart/form-data',
                    processData: false,   //当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                    error : function(request) {
                        parent.layer.alert("网络超时");
                    },
                    success: function (data) {
                        alert("上传成功！");
                    }
                });*/

            //发异步，把数据提交给php
            //
            $.post("{:url('ajax_add_notice')}",data.field,function(res){
                  if(res.status == 0){
                    layer.msg(res.message, {time: 3000});
                    var url = "{:url('home/index')}"; //
                      setTimeout(window.location.href=url,2000);
                    }else{
                     layer.msg(res.message, {time: 2000});
                  }
           
            });
            return false;
          });
          
          
        });
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
       <script type="text/javascript">
        var ue = UE.getEditor('container');
    </script>
  </body>

</html>